﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace DbView
{
	public partial class DatabaseSelectionForm : Form
	{
		String m_DatabaseSelectedOnOk = "";
		public DatabaseSelectionForm(List<String> DatabaseNames, string CurrentName)
		{
			InitializeComponent();

			foreach (String dbName in DatabaseNames)
			{
				this.listDatabases.Items.Add(dbName);
			}
			this.listDatabases.SelectedIndex = listDatabases.Items.IndexOf(CurrentName);
			if (this.listDatabases.SelectedIndex == -1)
				this.listDatabases.SelectedIndex = 0;
		}

		public string SelectedDatabase
		{
			get { return this.m_DatabaseSelectedOnOk; }
		}

		private void btnOk_Click(object sender, EventArgs e)
		{
			this.m_DatabaseSelectedOnOk = listDatabases.Items[listDatabases.SelectedIndex].ToString();
			this.DialogResult = DialogResult.OK;
			this.Close();
		}

		private void btnCancel_Click(object sender, EventArgs e)
		{
			this.DialogResult = DialogResult.Cancel;
			this.Close();
		}

		private void listDatabases_DoubleClick(object sender, EventArgs e)
		{
			this.btnOk_Click(sender, e);
		}

	}
}
